import ts from 'rollup-plugin-typescript2'

import serve from 'rollup-plugin-serve'

import {nodeResolve} from '@rollup/plugin-node-resolve'

import {fileURLToPath} from 'url'

import {dirname, resolve} from 'path'

const __filename = fileURLToPath(import.meta.url)


const __dirname = dirname(__filename)

export default {
    input: resolve(__dirname, 'src/index.ts'),
    output: {
        file: resolve(__dirname, 'dist/bundle.js'),
        format: 'iife',//输出文件类型, iife是立即执行函数
        sourcemap: true, //源码调试,
    },

    plugins: [
        nodeResolve({
            extensions: ['.js', '.ts'] //识别ts，js文件
        }),
        ts({
            tsconfig: resolve(__dirname, 'tsconfig.json'),//编译ts文件
        }),
        serve({
            open: true,//打开浏览器
            port: 3000,
            openPage: '/public/index.html',
        })
    ]
}